﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FbKPI.Facade;
using FbKPI.Model;

namespace FBKPI.Forms
{
    public partial class KPIAssignForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int ID = Convert.ToInt16(Request.QueryString["ID"]);
                if (ID != 0)
                {
                    KPIAssignFacade df = new KPIAssignFacade();
                    KPIAssign KPIs = df.GetKPIAssignByID(ID);

                    if (KPIs != null)
                    {
                        txt_id.Text = KPIs.ID.ToString();
                        txt_rgm.Text = KPIs.RGM == null ? "" : KPIs.RGM.Description;
                        txt_rgmid.Value = KPIs.RGM == null ? "" : KPIs.RGM.ID.ToString();
                        txt_location.Text = KPIs.Location == null ? "" : KPIs.Location.Description;
                        txt_locationid.Value = KPIs.Location == null ? "" : KPIs.Location.ID.ToString();
                        txt_subbranch.Text = KPIs.SubBranch == null ? "" : KPIs.SubBranch.Description;
                        txt_subbranchid.Value = KPIs.SubBranch == null ? "" : KPIs.SubBranch.ID.ToString();
                        chk_active.Checked = KPIs.isActive;
                        chk_weightenableflag.Checked = KPIs.WeightEnableFlag;
                        chk_uomenableflag.Checked = KPIs.UoMEnableFlag;
                        txt_uom.Text = KPIs.UoM == null ? "" : KPIs.UoM.Description;
                        txt_uomid.Value = KPIs.UoM == null ? "" : KPIs.UoM.ID.ToString();
                        txt_uommax.Text = KPIs.UoMDetailMax == null ? "" : KPIs.UoMDetailMax.Description;
                        txt_uommaxid.Value = KPIs.UoMDetailMax == null ? "" : KPIs.UoMDetailMax.ID.ToString();
                        txt_uommin.Text = KPIs.UoMDetailMin == null ? "" : KPIs.UoMDetailMin.Description;
                        txt_uomminid.Value = KPIs.UoMDetailMin == null ? "" : KPIs.UoMDetailMin.ID.ToString();
                        txt_kpi.Text = KPIs.KPI == null ? "" : KPIs.KPI.Description;
                        txt_kpiid.Value = KPIs.KPI == null ? "" : KPIs.KPI.ID.ToString();
                        txt_verifier.Text = KPIs.Verifier == null ? "" : KPIs.Verifier.FirstName + ' ' + KPIs.Verifier.LastName;
                        txt_verifierid.Value = KPIs.Verifier == null ? "" : KPIs.Verifier.ID.ToString();
                        txt_weight.Text = KPIs.Weight.ToString();
                        txt_polarization.Text = KPIs.Polarization;
                        txt_manualcalculation.Text = KPIs.ManualCalculation.ToString();
                        txt_lastmodifieddate.Text = KPIs.LastModifiedDate == null ? "" : Convert.ToDateTime(KPIs.LastModifiedDate).ToShortDateString();
                        txt_lastmodifiedby.Text = KPIs.LastModifiedBy;
                        txt_createdate.Text = KPIs.CreateDate == null ? "" : Convert.ToDateTime(KPIs.CreateDate).ToShortDateString();
                        txt_createby.Text = KPIs.CreateBy;
                    }
                }
                else
                {
                    txt_id.Text = "0";
                }

                if (txt_id.Text == "0") btn_delete.Visible = false;
            }
        }
    }
}